//
//  CCVideoDecoder.h
//  IntellDev_new
//
//  Created by os on 2021/3/12.
//

#import <Foundation/Foundation.h>
#import <AVFoundation/AVFoundation.h>

#import "CCAVConfig.h"

NS_ASSUME_NONNULL_BEGIN

// H.264 NAL type
typedef enum {
    H264NT_NAL = 0,
    H264NT_SLICE,
    H264NT_SLICE_DPA,
    H264NT_SLICE_DPB,
    H264NT_SLICE_DPC,
    H264NT_SLICE_IDR,
    H264NT_SEI,
    H264NT_SPS,
    H264NT_PPS,
} H264NALTYPE;

// NALU单元
typedef struct _NaluUnit {
    H264NALTYPE type;
    int size;
    unsigned char *data;
} NaluUnit;

@protocol CCVideoDecoderDelegate <NSObject>

/// 解码后H264数据回调
/// @param imageBuffer 解码后的数据
- (void)videoDecodedCallBack:(CVPixelBufferRef)imageBuffer;

- (void)videoDecodedCallBackWithSampleBuffer:(CMSampleBufferRef)sampleBuffer;

@end

@interface CCVideoDecoder : NSObject

@property (nonatomic, strong) CCVideoConfig *config;
@property (nonatomic, weak) id<CCVideoDecoderDelegate> videoDelegate;

/// 初始化解码器
- (instancetype)initWithConfig:(CCVideoConfig *)config;

- (void)decodeH264Frames:(uint8_t *)inputBuffer withLength:(int)length;

@end

NS_ASSUME_NONNULL_END
